package com.thti.mecool.client.service;

import org.jivesoftware.smack.ConnectionListener;

import com.thti.mecool.client.util.Util;

/**
 * 
 * @author weiguo.ren
 * 
 */

public class PersistentConnectionListener implements ConnectionListener {


    private final XmppManager xmppManager;

    public PersistentConnectionListener(XmppManager xmppManager) {
        this.xmppManager = xmppManager;
    }

    @Override
    public void connectionClosed() {
        Util.print( "connectionClosed()...");
    }

    @Override
    public void connectionClosedOnError(Exception e) {
        Util.print( "connectionClosedOnError()...");
        if (xmppManager.getConnection() != null
                && xmppManager.getConnection().isConnected()) {
            xmppManager.getConnection().disconnect();
        }
        xmppManager.startReconnectionThread();
    }

    @Override
    public void reconnectingIn(int seconds) {
        Util.print( "reconnectingIn()...");
    }

    @Override
    public void reconnectionFailed(Exception e) {
        Util.print( "reconnectionFailed()...");
    }

    @Override
    public void reconnectionSuccessful() {
        Util.print( "reconnectionSuccessful()...");
    }

}
